home *** CD-ROM | disk | FTP | other *** search
- package com.extensibility.xml;
-
- import com.extensibility.util.Debug;
- import com.extensibility.util.StringUtilities;
- import com.extensibility.xml.dt.DataType;
- import com.extensibility.xml.dt.DataTypeFactory;
- import com.extensibility.xml.dt.DataTypeIntf;
- import com.extensibility.xml.dt.Facet;
- import java.io.IOException;
- import java.io.Writer;
- import java.util.Enumeration;
- import java.util.Hashtable;
- import java.util.MissingResourceException;
- import java.util.Vector;
- import javax.swing.event.ChangeListener;
-
- public class AttributeDeclaration extends BaseDeclaration implements Cloneable, AttributeGroupMember, QualifiedName {
- public static final int UNKNOWN = 0;
- public static final int CDATA = 1;
- // $FF: renamed from: ID int
- public static final int field_0 = 2;
- public static final int IDREF = 3;
- public static final int IDREFS = 4;
- public static final int ENTITY = 5;
- public static final int ENTITIES = 6;
- public static final int NMTOKEN = 7;
- public static final int NMTOKENS = 8;
- public static final int NOTATION = 9;
- public static final int ENUMERATION = 10;
- Owner owner;
- boolean required;
- String defaultValue;
- DataType dataType;
- boolean isReferenceToGlobal;
- ChangeListener changerType;
-
- public AttributeDeclaration(String var1) {
- super(var1);
- this.required = false;
- this.changerType = new 1(this);
- this.setDataType(DataTypeFactory.createDataType(1), false);
- }
-
- public AttributeDeclaration(Owner var1, String var2, DataType var3, Vector var4, boolean var5, String var6) {
- this(var1, var2, var3, var5, var6);
- if (var4 != null && var4.size() > 0) {
- Facet var7 = new Facet(Facet.FACET_ENUM_NAME, var4);
- this.setDataType((DataType)this.dataType.applyFacet(var7), false);
- }
-
- }
-
- public AttributeDeclaration(Owner var1, String var2, DataType var3, boolean var4, String var5) {
- super(var2);
- this.required = false;
- this.changerType = new 1(this);
- this.owner = var1;
- this.setDataType(var3, false);
- this.required = var4;
- if (var5 != null) {
- this.defaultValue = var5;
- }
-
- }
-
- public AttributeDeclaration(Owner var1, String var2) {
- this(var1, var2, DataTypeFactory.createDataType(1), false, (String)null);
- }
-
- public Object clone(Owner var1) {
- AttributeDeclaration var2 = (AttributeDeclaration)this.clone();
- var2.owner = var1;
- if (var1 != null) {
- var1.add(var2);
- }
-
- return var2;
- }
-
- public BaseDeclaration clone(SchemaIntf var1, SchemaIntf var2, URI var3) {
- Owner var4 = this.getOwner();
- String var5 = var4.getName();
- Object var6;
- if (var4 instanceof InternalPEDeclaration) {
- var6 = (InternalPEDeclaration)var2.getNamedDeclaration(var5, Class.forName("com.extensibility.xml.InternalPEDeclaration"));
- } else {
- var6 = var2.getNamedElement(var5);
- }
-
- if (var6 == null) {
- var6 = var2.createUnknownOwner(var5);
- }
-
- AttributeDeclaration var7 = (AttributeDeclaration)this.clone((Owner)var6);
- ((BaseDeclaration)var7).setURI(var3);
- return var7;
- }
-
- public Object clone() {
- AttributeDeclaration var1 = null;
-
- try {
- var1 = (AttributeDeclaration)super.clone();
- if (this.dataType != null) {
- var1.setDataType((DataType)this.dataType.clone(), false);
- }
- } catch (CloneNotSupportedException var3) {
- Debug.assert(false, "Problem cloning AttributeDeclaration.");
- }
-
- return var1;
- }
-
- public String getPrefix() {
- int var1 = super.name.indexOf(58);
- return var1 == -1 ? null : super.name.substring(0, var1);
- }
-
- public String getNCName() {
- return super.name.substring(super.name.indexOf(58));
- }
-
- public String getNamespace() {
- if (this.getPrefix() == null) {
- return null;
- } else if (((BaseDeclaration)this).getSchema() == null) {
- return null;
- } else {
- NamespaceDeclaration var1 = ((BaseDeclaration)this).getSchema().getNamedNamespace(this.getPrefix());
- return var1 == null ? null : var1.getNamespace();
- }
- }
-
- public boolean isQualified() {
- return super.name.indexOf(58) >= 0;
- }
-
- public String getClassName() {
- return "com.extensibility.xml.AttributeDeclaration";
- }
-
- public void resetOwner() {
- this.owner = null;
- }
-
- public void setOwner(Owner var1) {
- Owner var2 = this.owner;
- if (var2 != var1) {
- this.owner = var1;
- ((BaseDeclaration)this).fireChangeEvent(12, var2);
- }
- }
-
- public boolean references(InternalPEDeclaration var1) {
- String var2 = String.valueOf("%").concat(String.valueOf(((BaseDeclaration)var1).getName()));
- if (this.defaultValue != null && this.defaultValue.indexOf(var2) >= 0) {
- return true;
- } else if (this.dataType.hasFacet(Facet.FACET_ENUM_NAME) && this.dataType.enumContains(var2)) {
- return true;
- } else {
- var2 = String.valueOf(String.valueOf("%").concat(String.valueOf(((BaseDeclaration)var1).getName()))).concat(String.valueOf(";"));
- if (this.defaultValue != null && this.defaultValue.indexOf(var2) >= 0) {
- return true;
- } else {
- return this.dataType.hasFacet(Facet.FACET_ENUM_NAME) && this.dataType.enumContains(var2);
- }
- }
- }
-
- public void setRequired(boolean var1) {
- this.required = var1;
- ((BaseDeclaration)this).fireChangeEvent(17, new Boolean(var1));
- }
-
- public void setOptions(String var1) {
- String var2 = this.getOptions();
- if (this.dataType != null) {
- this.setDataType((DataType)this.dataType.setOptions(var1), false);
- }
-
- ((BaseDeclaration)this).fireChangeEvent(15, var2);
- }
-
- public String getOptions() {
- return this.dataType == null ? new String("") : this.dataType.getOptions();
- }
-
- public Hashtable getChoicesExplains() {
- if (this.dataType != null) {
- Facet var1 = this.dataType.getFacet(Facet.FACET_ENUM_NAME);
- if (var1 != null) {
- return var1.getExplains();
- }
- }
-
- return null;
- }
-
- public void setChoices(Vector var1) {
- this.setChoices(var1, (Hashtable)null);
- }
-
- public void setChoices(Vector var1, Hashtable var2) {
- if (this.dataType != null) {
- Facet var4 = new Facet(Facet.FACET_ENUM_NAME, var1);
- if (var2 != null) {
- var4.setExplains(var2);
- }
-
- this.setDataType((DataType)this.dataType.applyFacet(var4), false);
- }
-
- ((BaseDeclaration)this).fireChangeEvent(15, var1);
- }
-
- public void setDefault(String var1) {
- String var2 = this.defaultValue;
- this.defaultValue = var1;
- ((BaseDeclaration)this).fireChangeEvent(16, var2);
- }
-
- public String getTypeForDisplay(SchemaIntf var1) {
- return var1.getDataTypeDisplay(this.dataType);
- }
-
- public boolean isID() {
- return this.dataType == DataTypeFactory.createDataType(2);
- }
-
- public Owner getOwner() {
- return this.owner;
- }
-
- public Vector getPrerequisites(SchemaIntf var1) {
- Vector var2 = super.getPrerequisites(var1);
- if (this.owner instanceof InternalPEDeclaration) {
- var2.addElement(this.owner);
- }
-
- BaseDeclaration.addPrerequisite(var1, var2, this.getDefault(), false);
- BaseDeclaration.addPrerequisite(var1, var2, this.getDefault(), true);
- Vector var3 = this.getChoices();
- if (var3 != null) {
- for(int var4 = 0; var4 < var3.size(); ++var4) {
- BaseDeclaration.addPrerequisite(var1, var2, (String)var3.elementAt(var4), true);
- }
- }
-
- return var2;
- }
-
- public boolean isPrimitive() {
- return this.dataType == null || DataTypeFactory.isPrimitive(this.dataType) || this.dataType.equals(DataTypeFactory.createDataType(DataTypeIntf.NOTATED));
- }
-
- public String getTypeAsPrimitiveSource() {
- if (this.isPrimitive()) {
- if (this.dataType.equalsSource(DataTypeIntf.STRING)) {
- return "CDATA";
- } else {
- return this.dataType.isEnumeration() ? "" : this.dataType.getSource();
- }
- } else {
- return "CDATA";
- }
- }
-
- public String getDefaultSource(char var1, String var2) {
- if (this.required) {
- if (this.defaultValue == null) {
- return "#REQUIRED";
- } else if (this.isNmTokens() && this.defaultValue.indexOf(37) < 0 && this.defaultValue.indexOf(38) < 0) {
- Vector var3 = StringUtilities.parseNames(this.defaultValue);
- if (var3.size() % 2 == 0 && var3.size() != 0) {
- String var4 = " ";
- int var5 = 0;
-
- for(int var6 = var3.size() - 2; var6 >= 0; var6 -= 2) {
- var5 = Math.max(var5, ((String)var3.elementAt(var6)).length());
- }
-
- StringBuffer var7 = new StringBuffer();
- var7.append(var1);
- int var8 = 0;
-
- while(var8 < var3.size() - 1) {
- if (var8 > 0) {
- var7.append(BaseDeclaration.LINE_SEPARATOR);
- var7.append(var2);
- var7.append(" ");
- }
-
- String var9 = (String)var3.elementAt(var8++);
- String var10 = (String)var3.elementAt(var8++);
- var7.append(var9);
- var7.append(var4.substring(0, var5 - var9.length()));
- var7.append(" ");
- var7.append(var10);
- }
-
- var7.append(var1);
- return var7.toString();
- } else {
- return String.valueOf("#FIXED ").concat(String.valueOf(StringUtilities.doubleQuoted(this.defaultValue)));
- }
- } else {
- return String.valueOf("#FIXED ").concat(String.valueOf(StringUtilities.quoted(this.defaultValue, var1)));
- }
- } else {
- return this.defaultValue == null ? "#IMPLIED" : StringUtilities.quoted(this.defaultValue, var1);
- }
- }
-
- public boolean isNmTokens() {
- return this.dataType.isNmTokens();
- }
-
- public boolean isNotation() {
- return this.dataType.isNotation();
- }
-
- public boolean isEnumeration() {
- return this.dataType.isEnumeration();
- }
-
- public String getChoicesSource(String var1) {
- if (!this.isNotation() && !this.isEnumeration()) {
- return "";
- } else {
- StringBuffer var2 = new StringBuffer(" (");
- Vector var3 = this.getChoices();
- if (var3 != null) {
- if (var1 != null) {
- int var4 = 2 + var1.length();
-
- for(int var5 = 0; var5 < var3.size() - 1; ++var5) {
- var4 += ((String)var3.elementAt(var5)).length() + 3;
- }
-
- if (var4 < 80) {
- var1 = null;
- }
- }
-
- Enumeration var6 = var3.elements();
-
- while(var6.hasMoreElements()) {
- var2.append(DTDUtilities.convertPEReferences((String)var6.nextElement(), true));
- if (var6.hasMoreElements()) {
- var2.append(" | ");
- if (var1 != null) {
- var2.append(BaseDeclaration.LINE_SEPARATOR);
- var2.append(var1);
- var2.append(" ");
- }
- }
- }
- }
-
- var2.append(" ) ");
- return var2.toString();
- }
- }
-
- public boolean getRequired() {
- return this.required;
- }
-
- public Vector getChoices() {
- Vector var1 = null;
- if (this.dataType.hasFacet(Facet.FACET_ENUM_NAME)) {
- Facet var2 = this.dataType.getFacet(Facet.FACET_ENUM_NAME);
- if (var2 != null) {
- var1 = (Vector)var2.getValue();
- }
- }
-
- return var1;
- }
-
- private void expandChoices(Enumeration var1, Vector var2) {
- while(var1.hasMoreElements()) {
- String var3 = ((String)var1.nextElement()).trim();
- if (var3.length() > 0 && var3.charAt(0) == '%') {
- String var4 = super.schema.expandPERefs(var3, this);
- if (var4.indexOf("|") != -1) {
- Enumeration var5 = StringUtilities.extract(var4, "|").elements();
- this.expandChoices(var5, var2);
- } else {
- var2.addElement(var4);
- }
- } else {
- var2.addElement(var3);
- }
- }
-
- }
-
- public Enumeration getChoices(SchemaIntf var1, boolean var2) {
- Vector var3 = this.getChoices();
- if (var3 == null) {
- return (new Vector()).elements();
- } else if (!var2) {
- return var3.elements();
- } else {
- Vector var4 = new Vector();
- this.expandChoices(var3.elements(), var4);
- return var4.elements();
- }
- }
-
- public String getDefault() {
- return this.defaultValue;
- }
-
- public void checkForErrors(SchemaIntf var1) {
- super.checkForErrors(var1);
- if (this.owner instanceof ElementDeclaration && var1.getNamedDeclaration(this.owner.getName(), Class.forName("com.extensibility.xml.ElementDeclaration")) == null) {
- super.errors.addElement(new ParserException(215, this.owner.getName()));
- }
-
- if ((!this.isGlobal() || !var1.isSupported("GESTALT_GLOBAL_ATTRS")) && !this.isOwnerDeclared()) {
- super.errors.addElement(new ParserException(215, this.owner.getName()));
- }
-
- if (this.isReference() && this.getReferent(var1) == null) {
- super.errors.addElement(new ParserException(264, ((BaseDeclaration)this).getName()));
- }
-
- if (this.isGlobal()) {
- AttributeDeclaration var2 = var1.getNamedAttribute((String)null, ((BaseDeclaration)this).getName());
- if (var2 != null && var2 != this) {
- super.errors.addElement(new ParserException(265, ((BaseDeclaration)this).getName()));
- }
- }
-
- if (this.getDataType().equals(2) && this.defaultValue != null && this.defaultValue.length() > 0) {
- super.errors.addElement(new ParserException(216, this.defaultValue));
- }
-
- if (((BaseDeclaration)this).getName().equals("xmlns")) {
- super.errors.addElement(new ParserException(271, ((BaseDeclaration)this).getName()));
- }
-
- if (this.getDataType().isNotation()) {
- Vector var6 = this.getChoices();
- if (var6 != null && var6.size() > 0) {
- if (var6.size() != 1 || ((String)var6.elementAt(0)).length() != 0) {
- for(int var3 = 0; var3 < var6.size(); ++var3) {
- if (!DTDParser.isName((String)var6.elementAt(var3))) {
- super.errors.addElement(new ParserException(217, (String)var6.elementAt(var3)));
- }
- }
- } else {
- super.errors.addElement(new ParserException(234, ""));
- }
- } else {
- super.errors.addElement(new ParserException(234, ""));
- }
- }
-
- if (this.defaultValue != null && this.defaultValue.length() > 0) {
- if ((this.getDataType().equals(2) || this.getDataType().equals(3) || this.getDataType().equals(5)) && !DTDParser.isName(this.defaultValue)) {
- super.errors.addElement(new ParserException(217, this.defaultValue));
- }
-
- if ((this.getDataType().equals(4) || this.getDataType().equals(6)) && !DTDParser.isNames(this.defaultValue)) {
- super.errors.addElement(new ParserException(217, this.defaultValue));
- }
-
- if (this.getDataType().equals(7) && !DTDParser.isNmToken(this.defaultValue)) {
- super.errors.addElement(new ParserException(217, this.defaultValue));
- }
-
- if (this.getDataType().equals(8) && !DTDParser.isNmTokens(this.defaultValue)) {
- super.errors.addElement(new ParserException(217, this.defaultValue));
- }
-
- if (this.getDataType().equals(5) || this.getDataType().equals(6)) {
- try {
- Vector var7 = DTDUtilities.parseNameList(this.defaultValue, '\u0000');
-
- for(int var9 = 0; var9 < var7.size(); ++var9) {
- ExternalGEDeclaration var4 = (ExternalGEDeclaration)var1.getNamedDeclaration((String)var7.elementAt(var9), Class.forName("com.extensibility.xml.ExternalGEDeclaration"));
- if (var4 == null) {
- super.errors.addElement(new ParserException(218, this.defaultValue));
- } else if (!var4.isUnparsed()) {
- super.errors.addElement(new ParserException(219, this.defaultValue));
- }
- }
- } catch (ParserException var5) {
- super.errors.addElement(new ParserException(220, this.defaultValue));
- }
- }
-
- if (this.dataType != null && this.dataType.hasFacet(Facet.FACET_ENUM_NAME)) {
- Enumeration var8 = this.getChoices(var1, true);
- boolean var10 = false;
-
- while(var8.hasMoreElements() && !var10) {
- String var11 = (String)var8.nextElement();
- if (this.defaultValue != null && this.defaultValue.equals(var11)) {
- var10 = true;
- }
- }
-
- if (!var10) {
- super.errors.addElement(new ParserException(235, this.defaultValue == null ? "" : this.defaultValue));
- }
- }
- }
-
- }
-
- public boolean equals(AttributeDeclaration var1) {
- Debug.assert(false, "Get rid of all equals calls on AttributeDeclaration");
- return this.canAggregateWith(var1);
- }
-
- public boolean canAggregateWith(AttributeDeclaration var1) {
- return this.required == var1.getRequired() && super.name.equals(((BaseDeclaration)var1).getName()) && (this.defaultValue == null ? var1.getDefault() == null : this.defaultValue.equals(var1.getDefault())) && this.dataType.equals(var1.dataType);
- }
-
- public int compareTo(AttributeDeclaration var1) {
- Debug.assert(false, "Get rid of all compareTo calls on AttributeDeclaration");
- return this.compareAttrTo(var1);
- }
-
- public int compareAttrTo(AttributeDeclaration var1) {
- int var2 = super.errors.size() - var1.errors.size();
- if (var2 != 0) {
- return var2;
- } else {
- var2 = super.name.compareTo(((BaseDeclaration)var1).getName());
- if (var2 != 0) {
- return var2;
- } else {
- var2 = (this.required ? 1 : 0) - (var1.getRequired() ? 1 : 0);
- if (var2 != 0) {
- return var2;
- } else {
- var2 = (this.defaultValue != null ? 1 : 0) - (var1.getDefault() != null ? 1 : 0);
- if (var2 != 0) {
- return var2;
- } else {
- if (this.defaultValue != null) {
- var2 = this.defaultValue.compareTo(var1.getDefault());
- if (var2 != 0) {
- return var2;
- }
- }
-
- var2 = ((BaseDeclaration)this).getURI().compareTo(((BaseDeclaration)var1).getURI());
- if (var2 != 0) {
- return var2;
- } else {
- var2 = this.dataType.compareTo(var1.dataType);
- if (var2 != 0) {
- return var2;
- } else {
- var2 = (this.getChoices() != null ? 1 : 0) - (var1.getChoices() != null ? 1 : 0);
- if (var2 != 0) {
- return var2;
- } else {
- if (this.getChoices() != null) {
- Enumeration var3 = this.getChoices().elements();
- Enumeration var4 = var1.getChoices().elements();
-
- while(var3.hasMoreElements()) {
- if (!var4.hasMoreElements()) {
- return 1;
- }
-
- var2 = ((String)var3.nextElement()).compareTo((String)var4.nextElement());
- if (var2 != 0) {
- return var2;
- }
- }
-
- if (var4.hasMoreElements()) {
- return -1;
- }
- }
-
- if (super.errors.size() > 0) {
- return -1;
- } else {
- return !this.isGlobal() && !var1.isGlobal() ? 0 : -1;
- }
- }
- }
- }
- }
- }
- }
- }
- }
-
- public String getSource() {
- String var1 = this.owner.getName();
- if (var1.length() == 0) {
- var1 = "MISSING_NAME";
- }
-
- StringBuffer var2 = new StringBuffer("<!ATTLIST ");
- var2.append(String.valueOf(String.valueOf(String.valueOf(String.valueOf(String.valueOf(this.owner.getName()).concat(String.valueOf(" "))).concat(String.valueOf(super.name))).concat(String.valueOf(" "))).concat(String.valueOf(this.getTypeAsPrimitiveSource()))).concat(String.valueOf(" ")));
- var2.append(this.getChoicesSource((String)null));
- var2.append(this.getDefaultSource('"', (String)null));
- var2.append(String.valueOf(">").concat(String.valueOf(BaseDeclaration.LINE_SEPARATOR)));
- return var2.toString();
- }
-
- boolean isOwnerDeclared() {
- return this.getOwner() instanceof ElementDeclaration || this.getOwner() instanceof InternalPEDeclaration;
- }
-
- public boolean isGlobal() {
- return !this.isOwnerDeclared() && this.owner != null && this.owner.getName().length() == 0;
- }
-
- public boolean isReference() {
- return this.isReferenceToGlobal && !this.isGlobal();
- }
-
- public void setReference(boolean var1) {
- this.isReferenceToGlobal = var1;
- }
-
- public AttributeDeclaration getReferent(SchemaIntf var1) {
- return !this.isReference() ? null : var1.getNamedAttribute((String)null, ((BaseDeclaration)this).getName());
- }
-
- public void write(Writer var1) throws IOException {
- if (!this.isOwnerDeclared()) {
- super.write(var1);
- }
- }
-
- private void setDataType(DataType var1, boolean var2) {
- DataType var3 = this.dataType;
- if (this.dataType != null) {
- this.dataType.release();
- this.dataType.removeChangeListener(this.changerType);
- }
-
- this.dataType = var1;
- if (this.dataType != null) {
- if (((BaseDeclaration)this).getSchema() != null) {
- this.dataType.bind(((BaseDeclaration)this).getSchema());
- }
-
- this.dataType.addChangeListener(this.changerType);
- }
-
- if (var2) {
- ((BaseDeclaration)this).fireChangeEvent(14, var3);
- }
-
- }
-
- public void setDataType(DataType var1) {
- this.setDataType(var1, true);
- }
-
- public DataType getDataType() {
- return this.dataType;
- }
-
- public String getSampleData() {
- if (super.sampleData == null) {
- String var1 = this.getDefault();
- if (var1 == null) {
- var1 = this.getRequired() ? "required" : "optional";
- }
-
- if (this.getDataType() != null) {
- try {
- var1 = BaseDeclaration.resourceBundle.getString(String.valueOf("xml.exemplar.dt.").concat(String.valueOf(this.getDataType().getSource())));
- } catch (MissingResourceException var3) {
- }
- }
-
- return var1;
- } else {
- return super.sampleData;
- }
- }
-
- protected void releaseBindings() {
- if (this.dataType != null) {
- this.dataType.release();
- }
-
- }
-
- protected void establishBindings() {
- if (this.dataType != null) {
- this.dataType.bind(((BaseDeclaration)this).getSchema());
- }
-
- }
- }
-